package cn.edu.flink.tutorial.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

public class UDSourceFunction implements SourceFunction<Long> {
    @Override
    public void run(SourceContext<Long> sourceContext) throws Exception {
        for (int i = 10000; true; i++) {
            sourceContext.collect(System.currentTimeMillis());
            Thread.sleep(3000L);
        }
    }

    @Override
    public void cancel() {

    }


    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 读取数据
        DataStreamSource<Long> dataStream = env.addSource(new UDSourceFunction());

        // 2.打印
        dataStream.print().setParallelism(1);

        // 3.执行
        env.execute();
    }
}
